import config from "../settings";
import Vue from 'vue'
import {ACCESS_TOKEN} from '@/store/mutation-types'

const TokenStorageUtil = {
  get() {
    if (config.tokenStorageType === 'local') {
      return Vue.ls.get(ACCESS_TOKEN)
    } else {
      return sessionStorage.getItem(ACCESS_TOKEN)
    }
  },
  set(token) {
    if (config.tokenStorageType === 'local') {
      Vue.ls.set(ACCESS_TOKEN, token, 7 * 24 * 60 * 60 * 1000)
    } else {
      sessionStorage.setItem(ACCESS_TOKEN, token)
    }
  },
  remove() {
    if (config.tokenStorageType === 'local') {
      Vue.ls.remove(ACCESS_TOKEN)
    } else {
      sessionStorage.removeItem(ACCESS_TOKEN)
    }
  }
}
export default TokenStorageUtil;
